<!--页面主要内容-->
<main class="lyear-layout-content">

	<div class="container-fluid p-t-15">

		<div class="row">
			<div class="col-lg-12">
				<div class="card">

					<div class="card-toolbar d-flex flex-column flex-md-row">
						<div class="toolbar-btn-action">
							<a class="btn btn-danger del" href="#!"><i class="mdi mdi-window-close "></i>删除</a>
						</div>

						<form class="search-bar ml-md-auto" method="get" action="#!" role="form">
							<input type="hidden" name="search_field" id="search-field" value="title" />
							<div class="input-group ml-md-auto">
								<div class="input-group-prepend">
									<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"
										aria-haspopup="true" aria-expanded="false" id="search-btn">标题</button>
									<div class="dropdown-menu" style="">
										<a class="dropdown-item" href="#!" data-field="title">标题</a>
										<a class="dropdown-item" href="#!" data-field="cat_name">栏目</a>
									</div>
								</div>
								<input type="text" class="form-control" name="keyword" placeholder="请输入名称">
							</div>
						</form>
					</div>
					<div class="card-body">

						<div class="table-responsive">
							<table class="table table-bordered">
								<thead>
									<tr style="text-align: center;">
										<th>
											<div class="custom-control custom-checkbox">
												<input type="checkbox" class="custom-control-input" id="check-all">
												<label class="custom-control-label" for="check-all"></label>
											</div>
										</th>
										<th>评论ID</th>
										<th>评论人</th>
										<th>订单商品</th>
										<th>商品数量</th>
										<th>商品单价</th>
										<th>商品总价</th>
										<th>评分</th>
										<th>商品评论</th>
										<th>商品评价图片</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody style="text-align: center;">
									{foreach $Orderductlist as $key => $item}
									<tr>
										<td>
											<div class="custom-control custom-checkbox">
												<input type="checkbox" class="custom-control-input ids" name="ids[]"
													value="{$item.id}" id="{$item.id}">
												<label class="custom-control-label" for="{$item.id}"></label>
											</div>
										</td>
										<td>{$item['id']}</td>
										<td>{$item['user']['nickname']}</td>
										<td>
											<img width="110" height="60" src="{$item['product']['cover_cdn']}" alt="">
										</td>
										<td>{$item['nums']}</td>
										<td>{$item['price']}</td>
										<td>{$item['total']}</td>
										<td>
											{if condition="$item['rate']"}
												<?php for($num = 1; $num <= $item['rate']; $num++){ ?>
													<i style="color: red;" class="layui-icon layui-icon-star-fill">&#xe658;</i> 
												<?php } ?>
											{else/}
												<span style="color: red;">暂无评分</span>
											{/if}
											
										</td>
										<td>
											{if condition="$item['comment']"}
												<textarea style="border:none;outline: none;resize: none;">{$item['comment']}</textarea>
											{else/}
												<span style="color: red;">暂无评论</span>
											{/if}
											
										</td>
										
										<td>
											{if condition="$item['proimg_cdn'] == []"}
												<span style="color: red;">暂无评论图片</span>
											{else/}
												{foreach $item['proimg_cdn'] as $keys => $val}
													<img width="50" height="70" src="{$val}" />
												{/foreach}
											{/if}
										</td>
										<td>
											<a class="btn btn-xs btn-default ajax-get confirm del" data-id="{$item['id']}"
												href="#" title=""
												data-toggle="tooltip" data-original-title="删除"><i class="mdi mdi-window-close"></i></a>
											</div>
										</td>

									</tr>
									{/foreach}

								</tbody>
							</table>
						</div>

						<!-- 分页 -->
						{$Orderductlist->render()}

					</div>
				</div>
			</div>

		</div>

</main>
<!--End 页面主要内容-->
<script type="text/javascript">
	function GetId() {
		// 存放id的数组
		let list = []

		$('input[name="ids[]"]:checked').each(function() {
			// console.log(item);
			list.push($(this).val())
		})

		return list
	}

	layui.use(['layer'], function() {
		layer = layui.layer

		// 删除分类
		$('.del').click(function() {

			let id = $(this).data('id');

			let str = GetId().join(',');

			$.ajax({
				type: 'post',
				url: `{:url('admin/order/delproduct')}`,
				data: {
					id,
					str
				},
				dataType: 'json',
				success: function(res) {
					if (res.code === 1) {
						layer.msg(res.msg, {
							icon: 1
						}, function() {
							location.href = 'orderproduct';
						})
					} else {
						layer.msg(res.msg, {
							icon: 5
						})
					}
				}
			})

		})

	})
</script>
